package com.weaver.openapi.service;

import com.weaver.openapi.pojo.user.params.*;
import com.weaver.openapi.util.*;
import cn.hutool.http.*;
import java.util.*;
import com.weaver.openapi.pojo.user.res.vo.*;
import com.weaver.openapi.pojo.user.res.*;
import com.alibaba.fastjson.*;
import com.weaver.openapi.pojo.*;

public class UserService
{
    public static NormalRes<UserCreate> createUserV3(final UserVo userVo, String host, final Map<String, String> headers) {
        host = HostUtil.beforeRequestCheckHeaders(host, headers, "application/x-www-form-urlencoded");
        final Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("access_token", userVo.getAccessToken());
        paramMap.put("name", userVo.getName());
        paramMap.put("mobile", userVo.getMobile());
        paramMap.put("department", userVo.getDepartment());
        paramMap.put("email", userVo.getEmail());
        paramMap.put("jobNum", userVo.getJobNum());
        paramMap.put("telephone", userVo.getTelephone());
        paramMap.put("hireDate", userVo.getHireDate());
        paramMap.put("sex", userVo.getSex());
        final String resJson = ((HttpRequest)HttpRequest.post(host + "/user/v3/createUser").form((Map)paramMap).headerMap((Map)headers, true)).execute().body();
        return transferResult(resJson);
    }
    
    public static NormalRes<UserCreate> createUserV4(final UserVo userVo, String host, final Map<String, String> headers) {
        host = HostUtil.beforeRequestCheckHeaders(host, headers, "application/x-www-form-urlencoded");
        final Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("access_token", userVo.getAccessToken());
        paramMap.put("userid", userVo.getUserid());
        paramMap.put("name", userVo.getName());
        paramMap.put("mobile", userVo.getMobile());
        paramMap.put("department", userVo.getDepartment());
        paramMap.put("email", userVo.getEmail());
        paramMap.put("jobNum", userVo.getJobNum());
        paramMap.put("telephone", userVo.getTelephone());
        paramMap.put("hireDate", userVo.getHireDate());
        paramMap.put("sex", userVo.getSex());
        paramMap.put("position", userVo.getPosition());
        paramMap.put("grade", userVo.getGrade());
        paramMap.put("superior", userVo.getSuperior());
        paramMap.put("assistant", userVo.getAssistant());
        paramMap.put("access", userVo.getAccess());
        paramMap.put("idNo", userVo.getIdNo());
        paramMap.put("birthday", userVo.getBirthday());
        paramMap.put("age", userVo.getAge());
        paramMap.put("maritalStatus", userVo.getMaritalStatus());
        paramMap.put("education", userVo.getEducation());
        paramMap.put("degree", userVo.getDegree());
        paramMap.put("graduateSchool", userVo.getGraduateSchool());
        paramMap.put("graduateDate", userVo.getGraduateDate());
        paramMap.put("nativePlace", userVo.getNativePlace());
        paramMap.put("nation", userVo.getNation());
        paramMap.put("householdType", userVo.getHouseholdType());
        paramMap.put("politicsStatus", userVo.getPoliticsStatus());
        paramMap.put("residencePlace", userVo.getResidencePlace());
        paramMap.put("familyContact", userVo.getFamilyContact());
        paramMap.put("firstWorkDate", userVo.getFirstWorkDate());
        paramMap.put("workYear", userVo.getWorkYear());
        paramMap.put("alias", userVo.getAlias());
        paramMap.put("childStatus", userVo.getChildStatus());
        paramMap.put("formDataMap", userVo.getFormDataMap());
        paramMap.put("otherSuperior", userVo.getOtherSuperior());
        paramMap.put("password", userVo.getPassword());
        final String resJson = ((HttpRequest)HttpRequest.post(host + "/user/v4/createUser").form((Map)paramMap).headerMap((Map)headers, true)).execute().body();
        return transferResult(resJson);
    }
    
    public static MessageResult updateUserV3(final UserVo userVo, String host, final Map<String, String> headers) {
        host = HostUtil.beforeRequestCheckHeaders(host, headers, "application/x-www-form-urlencoded");
        final Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("access_token", userVo.getAccessToken());
        paramMap.put("optId", userVo.getOptId());
        paramMap.put("userid", userVo.getUserid());
        paramMap.put("wechatUserId", userVo.getWechatUserId());
        paramMap.put("name", userVo.getName());
        paramMap.put("mobile", userVo.getMobile());
        paramMap.put("department", userVo.getDepartment());
        paramMap.put("email", userVo.getEmail());
        paramMap.put("jobNum", userVo.getJobNum());
        paramMap.put("telephone", userVo.getTelephone());
        paramMap.put("hireDate", userVo.getHireDate());
        paramMap.put("sex", userVo.getSex());
        paramMap.put("position", userVo.getPosition());
        paramMap.put("grade", userVo.getGrade());
        paramMap.put("superior", userVo.getSuperior());
        paramMap.put("assistant", userVo.getAssistant());
        paramMap.put("access", userVo.getAccess());
        paramMap.put("idNo", userVo.getIdNo());
        paramMap.put("birthday", userVo.getBirthday());
        paramMap.put("age", userVo.getAge());
        paramMap.put("maritalStatus", userVo.getMaritalStatus());
        paramMap.put("education", userVo.getEducation());
        paramMap.put("degree", userVo.getDegree());
        paramMap.put("graduateSchool", userVo.getGraduateSchool());
        paramMap.put("graduateDate", userVo.getGraduateDate());
        paramMap.put("nativePlace", userVo.getNativePlace());
        paramMap.put("nation", userVo.getNation());
        paramMap.put("householdType", userVo.getHouseholdType());
        paramMap.put("politicsStatus", userVo.getPoliticsStatus());
        paramMap.put("residencePlace", userVo.getResidencePlace());
        paramMap.put("familyContact", userVo.getFamilyContact());
        paramMap.put("firstWorkDate", userVo.getFirstWorkDate());
        paramMap.put("workYear", userVo.getWorkYear());
        paramMap.put("alias", userVo.getAlias());
        paramMap.put("childStatus", userVo.getChildStatus());
        paramMap.put("formDataMap", userVo.getFormDataMap());
        paramMap.put("otherSuperior", userVo.getOtherSuperior());
        final String resJson = ((HttpRequest)HttpRequest.post(host + "/user/v3/updateUser").form((Map)paramMap).headerMap((Map)headers, true)).execute().body();
        return (MessageResult)JSONObject.parseObject(resJson, (Class)MessageResult.class);
    }
    
    public static MessageResult updateUserV2(final UserVo userVo, String host, final Map<String, String> headers) {
        host = HostUtil.beforeRequestCheckHeaders(host, headers, "application/x-www-form-urlencoded");
        final Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("access_token", userVo.getAccessToken());
        paramMap.put("userid", userVo.getUserid());
        paramMap.put("name", userVo.getName());
        paramMap.put("mobile", userVo.getMobile());
        paramMap.put("department", userVo.getDepartment());
        paramMap.put("email", userVo.getEmail());
        paramMap.put("jobNum", userVo.getJobNum());
        paramMap.put("telephone", userVo.getTelephone());
        paramMap.put("hireDate", userVo.getHireDate());
        paramMap.put("sex", userVo.getSex());
        final String resJson = ((HttpRequest)HttpRequest.post(host + "/user/v2/updateUser").form((Map)paramMap).headerMap((Map)headers, true)).execute().body();
        return (MessageResult)JSONObject.parseObject(resJson, (Class)MessageResult.class);
    }
    
    public static MessageResult deleteUserV2(final UserVo userVo, String host, final Map<String, String> headers) {
        host = HostUtil.beforeRequestCheckHeaders(host, headers, "application/x-www-form-urlencoded");
        final Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("access_token", userVo.getAccessToken());
        paramMap.put("userid", userVo.getUserid());
        final String resJson = ((HttpRequest)HttpRequest.post(host + "/user/v2/delete").form((Map)paramMap).headerMap((Map)headers, true)).execute().body();
        return (MessageResult)JSONObject.parseObject(resJson, (Class)MessageResult.class);
    }
    
    public static NormalRes<List<UserResult>> findUserV3(final UserVo userVo, String host, final Map<String, String> headers) {
        host = HostUtil.beforeRequestCheckHeaders(host, headers, "application/x-www-form-urlencoded");
        final Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("access_token", userVo.getAccessToken());
        paramMap.put("userid", userVo.getUserid());
        paramMap.put("name", userVo.getName());
        paramMap.put("mobile", userVo.getMobile());
        paramMap.put("email", userVo.getEmail());
        paramMap.put("jobNum", userVo.getJobNum());
        final String resJson = ((HttpRequest)HttpRequest.get(host + "/user/v3/findUser").form((Map)paramMap).headerMap((Map)headers, true)).execute().body();
        return transferListResult(resJson);
    }
    
    public static UserResultVo findAllUsersV3(final UserVo userVo, String host, final Map<String, String> headers) {
        host = HostUtil.beforeRequestCheckHeaders(host, headers, "application/x-www-form-urlencoded");
        final Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("access_token", userVo.getAccessToken());
        paramMap.put("page", userVo.getPage());
        final String resJson = ((HttpRequest)HttpRequest.get(host + "/user/v3/findAllUsers").form((Map)paramMap).headerMap((Map)headers, true)).execute().body();
        return (UserResultVo)JSONObject.parseObject(resJson, (Class)UserResultVo.class);
    }
    
    public static UserResultVo getUsersV3(final UserVo userVo, String host, final Map<String, String> headers) {
        host = HostUtil.beforeRequestCheckHeaders(host, headers, "application/x-www-form-urlencoded");
        final Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("access_token", userVo.getAccessToken());
        paramMap.put("userid", userVo.getUserid());
        final String resJson = ((HttpRequest)HttpRequest.get(host + "/user/v3/get").form((Map)paramMap).headerMap((Map)headers, true)).execute().body();
        return (UserResultVo)JSONObject.parseObject(resJson, (Class)UserResultVo.class);
    }
    
    public static DepartmentUserResultVo departmentUsersV3(final UserVo userVo, String host, final Map<String, String> headers) {
        host = HostUtil.beforeRequestCheckHeaders(host, headers, "application/x-www-form-urlencoded");
        final Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("access_token", userVo.getAccessToken());
        paramMap.put("depid", userVo.getDepid());
        paramMap.put("status", userVo.getStatus());
        paramMap.put("fetch_child", userVo.getFetch_child());
        final String resJson = ((HttpRequest)HttpRequest.get(host + "/user/v3/departmentUsers").form((Map)paramMap).headerMap((Map)headers, true)).execute().body();
        return (DepartmentUserResultVo)JSONObject.parseObject(resJson, (Class)DepartmentUserResultVo.class);
    }
    
    public static UserResultVo findUpdateUserV3(final UserVo userVo, String host, final Map<String, String> headers) {
        host = HostUtil.beforeRequestCheckHeaders(host, headers, "application/x-www-form-urlencoded");
        final Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("access_token", userVo.getAccessToken());
        paramMap.put("beginDate", userVo.getBeginDate());
        paramMap.put("endDate", userVo.getEndDate());
        final String resJson = ((HttpRequest)HttpRequest.get(host + "/user/v3/findUpdateUser").form((Map)paramMap).headerMap((Map)headers, true)).execute().body();
        return (UserResultVo)JSONObject.parseObject(resJson, (Class)UserResultVo.class);
    }
    
    public static UserFieldResultVo queryUserInfoFieldsV4(final UserVo userVo, String host, final Map<String, String> headers) {
        host = HostUtil.beforeRequestCheckHeaders(host, headers, "application/x-www-form-urlencoded");
        final Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("access_token", userVo.getAccessToken());
        final String resJson = ((HttpRequest)HttpRequest.get(host + "/user/v4/queryUserInfoFields").form((Map)paramMap).headerMap((Map)headers, true)).execute().body();
        return (UserFieldResultVo)JSONObject.parseObject(resJson, (Class)UserFieldResultVo.class);
    }
    
    public static DeleteUserResultVo findAllPermanentlyDeleteUsersV3(final UserVo userVo, String host, final Map<String, String> headers) {
        host = HostUtil.beforeRequestCheckHeaders(host, headers, "application/x-www-form-urlencoded");
        final Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("access_token", userVo.getAccessToken());
        final String resJson = ((HttpRequest)HttpRequest.get(host + "/user/v3/findAllPermanentlyDeleteUsers").form((Map)paramMap).headerMap((Map)headers, true)).execute().body();
        return (DeleteUserResultVo)JSONObject.parseObject(resJson, (Class)DeleteUserResultVo.class);
    }
    
    public static NormalRes<List<UserResult>> findUserByWechatUserIdV3(final UserVo userVo, String host, final Map<String, String> headers) {
        host = HostUtil.beforeRequestCheckHeaders(host, headers, "application/x-www-form-urlencoded");
        final Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("access_token", userVo.getAccessToken());
        paramMap.put("wechatUserId", userVo.getWechatUserId());
        final String resJson = ((HttpRequest)HttpRequest.get(host + "/user/v3/findUserByWechatUserId").form((Map)paramMap).headerMap((Map)headers, true)).execute().body();
        return transferListResult(resJson);
    }
    
    public static RehireUserResultVo rehireEmployee(final UserVo userVo, String host, final Map<String, String> headers) {
        host = HostUtil.beforeRequestCheckHeaders(host, headers, "application/json");
        final Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("access_token", userVo.getAccessToken());
        paramMap.put("datas", userVo.getDatas());
        System.out.println(JSONObject.toJSONString((Object)paramMap));
        final String resJson = ((HttpRequest)HttpRequest.post(host + "/api/hrm/restful/rehireEmployee").body(JSON.toJSONString((Object)paramMap)).headerMap((Map)headers, true)).execute().body();
        return (RehireUserResultVo)JSONObject.parseObject(resJson, (Class)RehireUserResultVo.class);
    }
    
    public static NormalRes<UserCreate> transferResult(final String resJson) {
        final JSONObject jsonObject = JSONObject.parseObject(resJson);
        final UserCreate data = (UserCreate)jsonObject.getObject("data", (Class)UserCreate.class);
        final NormalResult message = (NormalResult)jsonObject.getObject("message", (Class)NormalResult.class);
        final NormalRes<UserCreate> normalRes = new NormalRes<UserCreate>();
        normalRes.setData(data);
        normalRes.setMessage(message);
        return normalRes;
    }
    
    public static NormalRes<List<UserResult>> transferListResult(final String resJson) {
        final JSONObject jsonObject = JSONObject.parseObject(resJson);
        final List<UserResult> data = (List<UserResult>)jsonObject.getJSONArray("data").toJavaList((Class)UserResult.class);
        final NormalResult message = (NormalResult)jsonObject.getObject("message", (Class)NormalResult.class);
        final NormalRes<List<UserResult>> normalRes = new NormalRes<List<UserResult>>();
        normalRes.setData(data);
        normalRes.setMessage(message);
        return normalRes;
    }
}
